package top.yxf.spring.test.bean.service;

import top.yxf.spring.beans.BeansException;
import top.yxf.spring.beans.DisposableBean;
import top.yxf.spring.beans.InitializingBean;
import top.yxf.spring.beans.factory.BeanClassLoaderAware;
import top.yxf.spring.beans.factory.BeanFactory;
import top.yxf.spring.beans.factory.BeanFactoryAware;
import top.yxf.spring.beans.factory.BeanNameAware;
import top.yxf.spring.context.ApplicationContext;
import top.yxf.spring.context.ApplicationContextAware;
import top.yxf.spring.test.bean.dao.IUserDao;
import top.yxf.spring.test.bean.dao.UserDao;

public class UserService implements InitializingBean, DisposableBean, BeanNameAware, BeanClassLoaderAware, BeanFactoryAware, ApplicationContextAware {

    private String name;

    private String userId;

    private IUserDao userDao;

    private String location;

    private String company;

    private ApplicationContext applicationContext;

    private BeanFactory beanFactory;

    public UserService() {

    }

    public UserService(String name) {
        this.name = name;
    }

    public String queryUser() {
        System.out.println("query user info  " + userDao.queryUserName(userId));
        return "query user info" + userDao.queryUserName(userId);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public String getCompany() {
        return company;
    }

    public void setCompany(String company) {
        this.company = company;
    }

    public void setUserDao(IUserDao userDao) {
        this.userDao = userDao;
    }

    public IUserDao getUserDao() {
        return userDao;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("执行：UserService.afterPropertiesSet");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("执行：UserService.destroy");
    }

    @Override
    public void setBeanClassLoader(ClassLoader classLoader) {
        System.out.println("ClassLoader：" + classLoader);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }

    @Override
    public void setBeanName(String beanName) {
        System.out.println("Bean Name is：" + beanName);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public BeanFactory getBeanFactory() {
        return beanFactory;
    }
}
